<template>
    <!-- 菜单列表 -->
    <div>
        <el-table row-key="id" :tree-props="{ children: 'children' }" default-expand-all :data="menuList" border
            style="width: 100%">
            <el-table-column prop="id" label="菜单编号" width="150">
            </el-table-column>
            <el-table-column prop="title" label="菜单名称" width="120">
            </el-table-column>
            <el-table-column prop="pid" label="上级菜单" width="120">
            </el-table-column>
            <el-table-column label="菜单图标" width="120">
                <template slot-scope="item">
                    <div>
                        <i :class="item.row.icon"></i>
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="url" label="菜单地址" width="300">
            </el-table-column>
            <el-table-column label="状态" width="120">
                <template slot-scope="item">
                    <div>
                        <el-tag v-if="item.row.status == 1" type="success">启用</el-tag>
                        <el-tag type="danger" v-else>禁用</el-tag>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="item">
                    <div>
                        <el-button type="primary" circle icon="el-icon-edit" @click="edit(item.row.id)">
                        </el-button>
                        <el-button type="danger" circle icon="el-icon-delete" @click="del(item.row.id)">
                        </el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
// 引入辅助性函数
import { mapGetters, mapActions } from "vuex";
// 引入封装好的接口
import { menuDelete } from "../../request/api"
export default {
    computed: {
        ...mapGetters({
            menuList: "menu/getMenuList"
        })
    },
    data() {
        return {
        };
    },
    methods: {
        // 点击编辑按钮
        edit(id) {
            this.$emit("edit", id)
        },
        // 获取菜单列表
        ...mapActions({
            getMenuList: 'menu/menuList_Action'
        }),
        // 点击删除按钮
        del(id) {
            // 调用删除接口
            this.$confirm("你确定要删除吗", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                menuDelete({
                    id,
                }).then((res) => {
                    if (res.code == 200) {
                        this.$message.success(res.msg);
                        //重新触发行动渲染
                        this.getMenuList();
                    }
                })
            }).catch(() => {
                this.$message.error("取消删除");
            })
        }
    },
    mounted() {
        //调用获取菜单列表
        this.getMenuList()
    }
};
</script>

<style scoped>
</style>
